package com.bnp.reporting.java8.date;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoField;
import java.util.Locale;

/**
 * Created by adib on 12/11/14.
 */
public class DateTimeFormatterExample {

    public static void main(String[] args) {

        LocalDate currentDate = LocalDate.now();
        DateTimeFormatter dateFormatter = DateTimeFormatter.ISO_DATE;
        System.out.println(dateFormatter.format(currentDate));

        LocalTime currentTime = LocalTime.now();
        DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_TIME;
        System.out.println(timeFormatter.format(currentTime));

        LocalDateTime currentDateTime = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME;
        System.out.println(dateTimeFormatter.format(currentDateTime));

        DateTimeFormatter formatterLong = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
        System.out.println(formatterLong.format(currentDateTime));

        DateTimeFormatter formatterShort = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
        System.out.println(formatterShort.format(currentDateTime));

        String french_Short = formatterShort.withLocale(Locale.FRENCH).format(currentDateTime);
        String french_Long = formatterLong.withLocale(Locale.FRENCH).format(currentDateTime);
        System.out.println("French DT Short: " + french_Short);
        System.out.println("French DT Long: " + french_Long);

        DateTimeFormatterBuilder dateTimeFormatterBuilder = new DateTimeFormatterBuilder()
                .appendValue(ChronoField.MONTH_OF_YEAR).appendLiteral("||")
                .appendValue(ChronoField.DAY_OF_MONTH).appendLiteral("||")
                .appendValue(ChronoField.YEAR);
        DateTimeFormatter dateTimeFormatter1 = dateTimeFormatterBuilder.toFormatter();
        System.out.println(dateTimeFormatter1.format(currentDateTime));
    }
}
